package com.mooral.web.action.category;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.DynaActionForm;

import com.mooral.bean.Beans;
import com.mooral.bean.Bean;
import com.mooral.bean.Categories;
import com.mooral.bean.Category;
import com.mooral.context.Context;
import com.mooral.web.action.MooralAction;
import com.mooral.web.util.SorterUtils;

public class SearchAction extends MooralAction {

	
	public ActionForward perform(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response,
			Context context) throws Exception {

		DynaActionForm dform = (DynaActionForm) form;
		String parentId = (String) dform.get("query");

/*		Beans beans = new Beans();
		beans.populate(new Category(), "SELECT * FROM categories WHERE parent_id is null");
		
		request.setAttribute("categories", beans);
*/
		// Categorias
		Categories categories = new Categories();
		categories.populate("SELECT id, parent_id as parentId, name, slug FROM categories");
		request.setAttribute("categoriesToHTML",  (new SorterUtils()).sortCategoriesByDependencyToHTML(categories));
		
		return mapping.findForward(ACTION_SUCCESS);
	}


}
